package com.login.service.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.login.bean.Buyer;
import com.login.dao.impl.BuyerDaoImpl;

/**
 * Servlet implementation class BuyerInfoServlet
 */
@WebServlet("/BuyerInfoServlet")
public class BuyerInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BuyerDaoImpl buyerInfo=new BuyerDaoImpl();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuyerInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String realN=request.getParameter("realName");
		String contactN=request.getParameter("contactNumber");
		String address=request.getParameter("address");
		Buyer user=(Buyer)request.getSession().getAttribute("user");
		System.out.println(user.getName());
		if(user!=null){
			System.out.println("我是用户");
		}
		int result=buyerInfo.saveBuyerInformation(address, contactN,realN, user);
		if(result!=0){
			System.out.println("个人信息修改成功！");
			response.sendRedirect("BuyerIndex.jsp");
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
